import {request} from '../../../utils/http'

const app = getApp();
Page({
  data: {
    recordsItems: [],
    curTypeIndex: 0,
    activeCode:'all',
    page:1,
    detailKeys: [
      {key:'subscribeShop', label: '预约门店'},
      {key:'subscribePosition', label: '预约岗位'},
      {key:'subscribeService', label: '预约服务'},
      {key:'subscribeTime', label: '预约时长', desc: '分钟'},
      {key:'subscribeRemarks', label: '备注'},
    ],
    menuTypeList: [
      {
        title: "全部",
        code: "all"
      },
      {
        title: "待确认",
        code: "TO_CONFIRM"
      },
      {
        title: "已接受",
        code: "ACCEPRED"
      },
      {
        title: "已取消",
        code: "CANCELED"
      },
      {
        title: "已过期",
        code: "EXPIRED"
      }
    ],
    list:[],
    recordsMap: {}
  },
  onLoad(query) {
    this.getList()
  
  },
  
  getList(){
    request('/appointment/order_list', 'get', {
      page:this.data.page,
      status:this.data.activeCode
    }).then((res:any) => {
      if (res.code == 200) {
        console.log(res)
        let list = this.data.page == 1 ? [] : this.data.list;

        list = list.concat(res.data.data)
        this.setData({
          list
        })
      }
    })
  },
  goDetail(e){
    console.log(e.currentTarget.dataset)
    let { item } = e.currentTarget.dataset

    my.navigateTo({
      url:`/pages/reservation/records-detail/index?id=${item.id}`
    })

  },
  tabItemClick({ index }) {
    
    if (this.data.curTypeIndex === index) {
      return;
    }

    this.setData({
      curTypeIndex: index,
      activeCode:this.data.menuTypeList[index].code,
      page:1,
    }, () => {
       this.getList()
    });
  }
});
